package org.edu.modules.classChoise.controller;

import java.util.Arrays;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.net.URLDecoder;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.edu.common.api.vo.Result;
import org.edu.common.system.query.QueryGenerator;
import org.edu.common.util.oConvertUtils;
import org.edu.modules.classChoise.entity.VeJwXkmskc;
import org.edu.modules.classChoise.service.IVeJwXkmskcService;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import lombok.extern.slf4j.Slf4j;
import org.jeecgframework.poi.excel.ExcelImportUtil;
import org.jeecgframework.poi.excel.def.NormalExcelConstants;
import org.jeecgframework.poi.excel.entity.ExportParams;
import org.jeecgframework.poi.excel.entity.ImportParams;
import org.jeecgframework.poi.excel.view.JeecgEntityExcelView;
import org.edu.common.system.base.controller.BaseController;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import org.springframework.web.multipart.MultipartHttpServletRequest;
import org.springframework.web.servlet.ModelAndView;
import com.alibaba.fastjson.JSON;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.edu.common.aspect.annotation.AutoLog;

 /**
 * @Description: 选课模式课程明细
 * @Author:
 * @Date:   2021-05-14
 * @Version: V1.0
 */
@Api(tags="选课模式课程明细")
@RestController
@RequestMapping("/classChoise/veJwXkmskc")
@Slf4j
public class VeJwXkmskcController extends BaseController<VeJwXkmskc, IVeJwXkmskcService> {
	@Autowired
	private IVeJwXkmskcService veJwXkmskcService;
	
	/**
	 * 分页查询
	 * @param veJwXkmskc
	 * @param pageNo
	 * @param pageSize
	 * @param req
	 * @return
	 */
	@AutoLog(value = "选课模式课程明细-分页查询")
	@ApiOperation(value="分页查询", notes="选课模式课程明细-分页查询")
	@PostMapping(value = "/list")
	public Result<?> queryPageList(VeJwXkmskc veJwXkmskc,
								   @RequestParam(name="pageNo", defaultValue="1") Integer pageNo,
								   @RequestParam(name="pageSize", defaultValue="999") Integer pageSize,
								   HttpServletRequest req) {
		QueryWrapper<VeJwXkmskc> queryWrapper = QueryGenerator.initQueryWrapper(veJwXkmskc, req.getParameterMap());
		Page<VeJwXkmskc> page = new Page<VeJwXkmskc>(pageNo, pageSize);
		IPage<VeJwXkmskc> pageList = veJwXkmskcService.page(page, queryWrapper);
		return Result.OK(pageList);
	}

	/**
	* 通过id查询
	* @param id
	* @return
	*/
	@AutoLog(value = "选课模式课程明细-通过id查询")
	@ApiOperation(value="通过id查询", notes="选课模式课程明细-通过id查询")
	@PostMapping(value = "/queryById")
	public Result<?> queryById(@RequestParam(name="id",required=true) String id) {
		VeJwXkmskc veJwXkmskc = veJwXkmskcService.getById(id);
		if(veJwXkmskc==null) {
			return Result.error("未找到对应数据");
		}
		return Result.OK(veJwXkmskc);
	}
	
	/**
	 * 新增信息
	 * @return
	 */
	@AutoLog(value = "选课模式课程明细-批量保存")
	@ApiOperation(value="批量保存", notes="选课模式课程明细-批量保存")
	@PostMapping(value = "/saveBatch")
	public Result<?> saveBatch(@RequestBody List<VeJwXkmskc> veJwXkmskcList) {
		if(veJwXkmskcList.size()<1){
			return Result.error("选课模式课程不能为空!");
		}
		if(veJwXkmskcService.saveBatchByMsId(veJwXkmskcList)){
		   return Result.OK("批量保存成功！");
        }
        return Result.error("批量保存失败!");
	}
	
	/**
	 * 修改信息
	 * @param veJwXkmskc
	 * @return
	 */
	@AutoLog(value = "选课模式课程明细-修改信息")
	@ApiOperation(value="修改信息", notes="选课模式课程明细-修改信息")
	@PostMapping(value = "/edit")
	public Result<?> edit(@RequestBody VeJwXkmskc veJwXkmskc) {
        if(veJwXkmskcService.updateById(veJwXkmskc)){
		    return Result.OK("编辑成功!");
        }
        return Result.error("编辑失败!");
	}
	
	/**
	 * 通过id删除
	 * @param id
	 * @return
	 */
	@AutoLog(value = "选课模式课程明细-通过id删除")
	@ApiOperation(value="通过id删除", notes="选课模式课程明细-通过id删除")
	@PostMapping(value = "/delete")
	public Result<?> delete(@RequestParam(name="id",required=true) String id) {
        if(veJwXkmskcService.removeById(id)){
		    return Result.OK("删除成功!");
        }
        return Result.error("删除失败!");
	}
	
	/**
	 * 批量删除
	 * @param ids
	 * @return
	 */
	@AutoLog(value = "选课模式课程明细-批量删除")
	@ApiOperation(value="批量删除", notes="选课模式课程明细-批量删除")
	@PostMapping(value = "/deleteBatch")
	public Result<?> deleteBatch(@RequestParam(name="ids",required=true) String ids) {
		if(this.veJwXkmskcService.removeByIds(Arrays.asList(ids.split(",")))){
		         return Result.OK("批量删除成功!");
        }
        return Result.error("批量删除失败!");
	}

}
